﻿using System.Collections.Generic;
using System.Xml;

namespace Quail.Silverlight
{
    /// <summary>
    /// Wraps the ItemsControl
    /// </summary>
    public class SlvItemsControl : SlvControl
	{
        /// <summary>
        /// Initializes a new instance of the <see cref="SlvItemsControl"/> class.
        /// </summary>
        public SlvItemsControl()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SlvItemsControl"/> class.
        /// </summary>
        /// <param name="container">The container for the control.</param>
        /// <param name="selector">The selector.</param>
        public SlvItemsControl(SlvControlContainer container, string selector)
            : base(container, selector)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SlvItemsControl"/> class.
        /// </summary>
        /// <param name="control">The control.</param>
        public SlvItemsControl(SlvControl control)
            : base(control)
        {
        }

        /// <summary>
        /// Gets the Items count
        /// </summary>
        public int ItemsCount
        {
            get { return int.Parse(GetPropertyValue("ItemsCount")); }
        }

        /// <summary>
        /// Gets the count of checkboxes
        /// </summary>
        public int CheckBoxValuesCount
        {
            get { return int.Parse(GetPropertyValue("CheckBoxValues.length")); }
        }

        /// <summary>
        /// Gets the checkbox values
        /// </summary>
        public List<SlvCheckBox> CheckBoxValues
        {
            get
            {
                var checkList = new List<SlvCheckBox>();
                for (int i = 0; i < CheckBoxValuesCount; i++)
                {
                    checkList.Add(new SlvCheckBox(this, "checkbox:eq(" + i + ")"));
                }

                return checkList;
            }
        }

        /// <summary>
        /// Gets an array of values from the list
        /// </summary>
        public string[] Values
        {
            get
            {
                return GetPropertyValueArray("Values");
            }
        }

        /// <summary>
        /// Gets the array of values as an Xml string
        /// </summary>
        public XmlDocument ValuesAsXml
        {
            get
            {
                var dom = new XmlDocument();

                dom.LoadXml(GetPropertyValue("ValuesAsXml"));

                return dom;
            }
        }
    }
}
